﻿using ProjScan.RecordManager;
using ProjScan.RecordManager.AssetData;
using ProjScan.ScanRule.Attr;
using UnityEditor;
using UnityEngine;

namespace ProjScan.ScanRule.ProjectAssets.Model
{
    [ModelRuleAttr]
    internal class ImportMaterialNone : RecordRuleImp<ModelAssetData, ModelRecordManager>
    {
        protected override bool IsOK(ModelAssetData assetData)
        {
            if (!assetData.noImporter)
            {
                if (assetData.assetImporter.materialImportMode == ModelImporterMaterialImportMode.None)
                {
                    return false;
                }

                GameObject gameObject = AssetDatabase.LoadAssetAtPath<GameObject>(assetData.path);
                if (gameObject != null)
                {
                    Renderer[] componentsInChildren = gameObject.GetComponentsInChildren<Renderer>();
                    Renderer[] array = componentsInChildren;
                    foreach (Renderer renderer in array)
                    {
                        if (renderer.sharedMaterials == null)
                        {
                            continue;
                        }

                        UnityEngine.Material[] sharedMaterials = renderer.sharedMaterials;
                        foreach (UnityEngine.Material material in sharedMaterials)
                        {
                            if (material == null || material.shader.name.Equals("Standard"))
                            {
                                return false;
                            }
                        }
                    }
                }
            }

            return true;
        }
    }
}